using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Logging
{
    public class StreamHandler : Handler
    {

        private TextWriter writer;

        public StreamHandler(TextWriter writer, Formatter formatter)
        {
            this.writer = writer;
            base.Formatter = formatter;
        }

        public override void Close()
        {
            writer.Close();
        }

        public override void Flush()
        {
            writer.Flush();
        }

        public override void Publish(LogRecord record)
        {
            if (!IsLoggable(record)) return;
            writer.Write(Formatter.Format(record));
            writer.Flush();
        }
    }
}
